import click
from sensorapp import app, db
from sensorapp.models import Sensor


@app.cli.command()
def forge():
    """
    用于初始化数据库的指令， 在虚拟环境下运行： flask forge
    """
    db.create_all()
    # books = [
    #     {
    #         "title": "A Fire Upon the Deep",
    #         "author": "Vernor Vinge",
    #         "summary": "The coldsleep itself was dreamless.",
    #         "published": "1992",
    #     },
    #     {
    #         "title": "The Ones Who Walk Away From Omelas",
    #         "author": "Ursula K. Le Guin",
    #         "summary": "With a clamor of bells that set the swallows soaring, the Festival of Summer came to the city Omelas, bright-towered by the sea.",
    #         "published": "1973",
    #     },
    #     {
    #         "title": "Dhalgren",
    #         "author": "Samuel R. Delany",
    #         "summary": "to wound the autumnal city.",
    #         "published": "1975",
    #     },
    #     {
    #         "title": "JavaScript Programming",
    #         "author": "Samuel R. Delany",
    #         "summary": "to wound the autumnal city.",
    #         "published": "2015",
    #     },
    #     {
    #         "title": "Flask Web Development",
    #         "author": "Ursula K. Le Guin",
    #         "summary": "With a clamor of bells that set the swallows soaring, the Festival of Summer came to the city Omelas, bright-towered by the sea.",
    #         "published": "2018",
    #     },
    # ]

    # for item in books:
    #     book = Sensor(
    #         title=item["title"],
    #         author=item["author"],
    #         summary=item["summary"],
    #         published=item["published"],
    #     )
    #     db.session.add(book)
    db.session.commit()
    click.echo("database initialized.")
